package com.yun.controller;
import com.yun.pojo.BaseText;
import com.yun.pojo.User;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@CrossOrigin
public class DomainController {

    /**
     * 短域名存储接口，接受长域名，返回短域名非官方的
     * @return
     * @throws Exception
     */
    private static List<BaseText> list=new ArrayList<>();
    @RequestMapping(value = "put", method = RequestMethod.GET)
    @ApiOperation(value="短域名存储接口，接受长域名，返回短域名", notes="短域名存储接口，接受长域名，返回短域名")
    public String test1ss() throws Exception {

        return "123";
    }

    /**
     * 域名读取
     * @param sortDomain
     * @return
     * @throws Exception
     */
    @ApiOperation(value="短域名读取接口，接受段域名域名信息，返回长域名信息", notes="短域名读取接口，接受段域名域名信息，返回长域名信息")
    @RequestMapping(value = "get", method = RequestMethod.GET)
    public String  get(String sortDomain) throws Exception {
        List<BaseText> collect = list.stream().filter(x -> x.getSortDomain().equalsIgnoreCase(sortDomain)).collect(Collectors.toList());
        if (collect.isEmpty()) {
            return null;
        } else {
            return collect.get(0).getLongDomain().toString();
        }
    }




    /**
     * 域名读取
     * @param sortDomain
     * @return
     * @throws Exception
     */
    @ApiOperation(value="获取用户信息", notes="获取用户信息")
    @RequestMapping(value = "getUsers", method = RequestMethod.GET)
    public List<User>  getUsers(String currentPage,String pageSize) throws Exception {
        List<User> lists=new ArrayList<>();
        User user1=new User();
        user1.setAddress("Haha");
        user1.setDate("2021-12-12");
        user1.setName("张三");
        lists.add(user1);
        User user11=new User();
        user11.setAddress("Haha1");
        user11.setDate("2021-13-12");
        user11.setName("李四");
        lists.add(user11);
        return lists;

    }

}